package com.sr.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sr.data.*;

public class AddMore extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		moreDataService mds = new moreDataService();
		
		String projectName = request.getParameter("pName");
		
		srProject srp = new srProject();
		
		srp.setprojectName(request.getParameter("pName"));
		srp.setContract_Pic(request.getParameter("contract"));
		srp.setTotalMoney(Double.parseDouble(request.getParameter("money")));
		srp.setRealEndDate(request.getParameter("reDate"));
		srp.setCompletionTask(request.getParameter("completionTask"));
		srp.setPassAudit( request.getParameter("passAudit"));
		srp.setConclusionReport(request.getParameter("conclusionReport"));
		srp.setRank( request.getParameter("rank"));
		srp.setRankContent(request.getParameter("rankContent"));
		
		int count =mds.GetCountOfProjectName(projectName);
		if(count == 0){
			mds.AddProject(srp);
			srp = mds.CheckProject(srp);
			
			request.getSession().setAttribute("updateMoreProject", srp);
			response.sendRedirect("/scientific/jsp/more/moreUpdate.jsp");			
		}
		else{
			request.setAttribute("ExpAddError", "项目：'"+projectName+"'已存在，请重新输入!");
			request.setAttribute("updateMore", srp);
			request.getRequestDispatcher("/jsp/more/addMoreinfo.jsp").forward(request, response);	
		}	
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doGet(request, response);
	}
}
